package com.century.sjt.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.century.sjt.R;
import com.century.sjt.entity.BankCard;
import com.century.sjt.fragment.AddBankFragment_first;
import com.century.sjt.fragment.AddBankFragment_second;
import com.century.sjt.widget.TitleBar.SjtTitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author:周玲波
 * @Description:添加银行卡
 * @date : 2016/8/17 19:06
 */
public class AddBankActivity extends BaseActivity implements AddBankFragment_first.firstClickListener {
    @BindView(R.id.add_bank_titlebar)
    SjtTitleBar titleBar;
    AddBankFragment_first  firstFragment;
    AddBankFragment_second secondFragment;
    int index;

    private String userId,idCard,name,isRealName;
    private String phone,bankCardNo,bankCode,bankName,bankType,status;
    private  String Type = "0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sjt_add_bankcad_activity);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        Type=intent.getStringExtra("type");
        if (Type==null||Type.equals("")){
            Type="3";
        }
        Bundle bundle = getIntent().getExtras();
        if(bundle!=null){
            phone = bundle.getString("phone");
            if ("6".equals(Type)){
//                aMerchant=(MerchantList)getIntent().getSerializableExtra("Merchant");
            }
            bankCardNo = bundle.getString("bankCardNo");
            bankCode = bundle.getString("bankCode");
            bankName = bundle.getString("bankName");
            bankType = bundle.getString("bankType");
            status = bundle.getString("status");
        }
        initView();
        initData();
    }

    @Override
    protected void initView() {
        titleBar.setTitle(getResources().getString(R.string.text_bind_bank_card));
        titleBar.setLeftIconResource(getResources().getString(R.string.icon_return));
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (index){
                    case 1:
                        FragmentManager fm = getFragmentManager();
                        FragmentTransaction transaction = fm.beginTransaction();
                        if(firstFragment==null){
                            firstFragment=new AddBankFragment_first();
                        }
                        transaction.replace(R.id.sjt_bind_bank_fl,firstFragment);
                        transaction.commit();
                        index=0;
                        break;
                    default:
                        finish();
                        break;

                }


            }
        });

        if ("0".equals(status)){
            titleBar.setTitle(getResources().getString(R.string.tab_add_quickpay_card));
        }


    }

    @Override
    protected void initEvent() {



    }

    @Override
    protected void initData() {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        if(firstFragment==null){
            firstFragment=new AddBankFragment_first();
        }
        transaction.replace(R.id.sjt_bind_bank_fl,firstFragment);
        transaction.commit();
    }


    @Override
    public void onFirstClick(String userName, String idCard, BankCard bankCard, int index, String sn ,String type) {
       this.index=index;
        System.out.println("index=="+this.index);
       this.bankType=bankType;
        firstFragment=null;
        FragmentManager fm = getFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        if(secondFragment==null){
            secondFragment=new AddBankFragment_second();
        }
        transaction.replace(R.id.sjt_bind_bank_fl,secondFragment);
        transaction.commit();
        if(secondFragment instanceof secondClickListener ){
            secondFragment.onSecondClick(userName,idCard,bankCard,sn,type);
        }
    }
    public interface  secondClickListener{
        void onSecondClick(String userName, String idCard, BankCard bankCard,String sn,String type);
    }

}
